package com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.group_details;

import android.util.Log;

import com.wangjiyuan.giftshuo.bean.classifybean.strategy.GroupDetailsBean;
import com.wangjiyuan.giftshuo.config.classify.ClassifyURL;
import com.wangjiyuan.giftshuo.http.classityretrofitinterface.RetrofitInterface;
import com.wangjiyuan.giftshuo.utils.OkHttp3Helper;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * Created by QXL on 2016/11/22.
 */

public class GroupDetModel implements GroupDetContract.IContractModel {
    private int mId =111;

    @Override
    public Observable<GroupDetailsBean> getGroupDetailObservable(int mId,int limit, int offset, String order_by) {
//        OkHttp的Tag拦截器
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient okHttpSingletonInstance = OkHttp3Helper.getOkHttpSingletonInstance().newBuilder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request request = chain.request();
//                        Log.e("-----------", request.url().toString());
                        return chain.proceed(request);
                    }
                })
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ClassifyURL.BASE_URL)
                .client(okHttpSingletonInstance)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        RetrofitInterface retrofitInterface = retrofit.create(RetrofitInterface.class);
        Observable<GroupDetailsBean> groupDetailObservable =
                retrofitInterface.getGroupDetailObservable(mId, limit, offset, order_by);
        return groupDetailObservable;
    }
}
